<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>AI决策驾驶舱 - 智能量化投资平台</title>
    
    <!-- Bootstrap 5 CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- Font Awesome -->
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <!-- Chart.js -->
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    
    <style>
        :root {
            --primary-color: #2563eb;
            --success-color: #16a34a;
            --warning-color: #d97706;
            --danger-color: #dc2626;
            --info-color: #0891b2;
            --dark-color: #1f2937;
            --light-bg: #f8fafc;
            --card-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
        }

        body {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }

        .dashboard-container {
            background: var(--light-bg);
            min-height: 100vh;
            padding: 0;
        }

        .header-section {
            background: linear-gradient(135deg, var(--primary-color) 0%, #1e40af 100%);
            color: white;
            padding: 2rem 0;
            margin-bottom: 2rem;
        }

        .ai-card {
            background: white;
            border-radius: 16px;
            box-shadow: var(--card-shadow);
            border: none;
            transition: all 0.3s ease;
            height: 100%;
        }

        .ai-card:hover {
            transform: translateY(-4px);
            box-shadow: 0 8px 25px -5px rgba(0, 0, 0, 0.15);
        }

        .opportunity-card {
            border-left: 4px solid var(--success-color);
            position: relative;
            overflow: hidden;
        }

        .opportunity-card::before {
            content: '';
            position: absolute;
            top: 0;
            right: 0;
            width: 100px;
            height: 100px;
            background: linear-gradient(45deg, transparent 30%, rgba(22, 163, 74, 0.1) 100%);
            border-radius: 50%;
            transform: translate(30px, -30px);
        }

        .risk-card {
            border-left: 4px solid var(--danger-color);
        }

        .confidence-badge {
            background: linear-gradient(45deg, var(--success-color), #22c55e);
            color: white;
            padding: 0.5rem 1rem;
            border-radius: 50px;
            font-weight: 600;
            font-size: 0.9rem;
        }

        .rating-badge {
            padding: 0.4rem 1rem;
            border-radius: 20px;
            font-weight: 600;
            font-size: 0.85rem;
        }

        .rating-buy {
            background: linear-gradient(45deg, var(--success-color), #22c55e);
            color: white;
        }

        .rating-hold {
            background: linear-gradient(45deg, var(--warning-color), #f59e0b);
            color: white;
        }

        .rating-sell {
            background: linear-gradient(45deg, var(--danger-color), #ef4444);
            color: white;
        }

        .market-sentiment {
            background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
            color: white;
            border-radius: 16px;
            padding: 2rem;
        }

        .quick-action-btn {
            background: linear-gradient(45deg, var(--primary-color), #3b82f6);
            border: none;
            color: white;
            padding: 0.75rem 1.5rem;
            border-radius: 12px;
            font-weight: 600;
            transition: all 0.3s ease;
        }

        .quick-action-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 15px rgba(37, 99, 235, 0.3);
            color: white;
        }

        .stats-number {
            font-size: 2.5rem;
            font-weight: 700;
            background: linear-gradient(45deg, var(--primary-color), #3b82f6);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }

        .pulse-animation {
            animation: pulse 2s infinite;
        }

        @keyframes pulse {
            0% { transform: scale(1); }
            50% { transform: scale(1.05); }
            100% { transform: scale(1); }
        }

        .loading-skeleton {
            background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
            background-size: 200% 100%;
            animation: loading 1.5s infinite;
        }

        @keyframes loading {
            0% { background-position: 200% 0; }
            100% { background-position: -200% 0; }
        }

        .ai-thinking {
            background: linear-gradient(45deg, #667eea, #764ba2);
            color: white;
            padding: 1rem;
            border-radius: 12px;
            text-align: center;
            margin: 1rem 0;
        }
    </style>
</head>
<body>
    <div class="dashboard-container">
        <!-- 头部区域 -->
        <div class="header-section">
            <div class="container">
                <div class="row align-items-center">
                    <div class="col-md-8">
                        <h1 class="mb-2">
                            <i class="fas fa-robot me-3"></i>
                            AI决策驾驶舱
                        </h1>
                        <p class="mb-0 opacity-90">
                            <i class="fas fa-calendar-day me-2"></i>
                            今日投研摘要 · <span id="current-date"></span>
                        </p>
                    </div>
                    <div class="col-md-4 text-end">
                        <div class="d-flex justify-content-end align-items-center">
                            <div class="me-3">
                                <small class="opacity-75">AI服务状态</small><br>
                                <span id="ai-status" class="badge bg-success">
                                    <i class="fas fa-circle me-1"></i>正常运行
                                </span>
                            </div>
                            <button class="btn btn-light btn-sm" onclick="refreshDashboard()">
                                <i class="fas fa-sync-alt me-1"></i>刷新
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="container">
            <!-- 今日最优机会 -->
            <div class="row mb-4">
                <div class="col-12">
                    <div class="ai-card">
                        <div class="card-header bg-transparent border-0 pb-0">
                            <div class="d-flex justify-content-between align-items-center">
                                <h4 class="mb-0">
                                    <i class="fas fa-star text-warning me-2"></i>
                                    今日最优机会
                                </h4>
                                <span class="badge bg-primary">AI精选</span>
                            </div>
                            <p class="text-muted mb-0">AI从全市场筛选出的最具潜力投资机会</p>
                        </div>
                        <div class="card-body">
                            <div id="top-opportunities" class="row">
                                <!-- 机会卡片将通过JavaScript动态加载 -->
                                <div class="col-12">
                                    <div class="ai-thinking">
                                        <i class="fas fa-brain fa-spin me-2"></i>
                                        AI正在分析全市场数据，寻找最优投资机会...
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 我的持仓AI诊断 + 大盘AI洞察 -->
            <div class="row mb-4">
                <div class="col-lg-8">
                    <div class="ai-card">
                        <div class="card-header bg-transparent border-0">
                            <h5 class="mb-0">
                                <i class="fas fa-stethoscope text-info me-2"></i>
                                我的持仓AI诊断
                            </h5>
                            <small class="text-muted">AI实时监控您的投资组合风险与机会</small>
                        </div>
                        <div class="card-body">
                            <div id="portfolio-diagnosis">
                                <!-- 持仓诊断内容 -->
                                <div class="text-center py-4">
                                    <i class="fas fa-chart-pie fa-3x text-muted mb-3"></i>
                                    <p class="text-muted">暂无持仓数据</p>
                                    <button class="btn btn-outline-primary btn-sm" onclick="addPortfolio()">
                                        <i class="fas fa-plus me-1"></i>添加持仓
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-lg-4">
                    <div class="ai-card market-sentiment">
                        <h5 class="mb-3">
                            <i class="fas fa-globe me-2"></i>
                            大盘AI洞察
                        </h5>
                        <div id="market-insight">
                            <div class="text-center">
                                <div class="stats-number text-white">谨慎乐观</div>
                                <p class="mb-3 opacity-90">今日市场情绪</p>
                                <div class="progress mb-3" style="height: 8px;">
                                    <div class="progress-bar bg-warning" style="width: 65%"></div>
                                </div>
                                <small class="opacity-75">
                                    AI认为当前市场处于底部区域，但反弹仍需更多积极信号确认
                                </small>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 快速操作区域 -->
            <div class="row mb-4">
                <div class="col-12">
                    <div class="ai-card">
                        <div class="card-body">
                            <div class="row text-center">
                                <div class="col-md-3 mb-3">
                                    <button class="quick-action-btn w-100" onclick="goToStockScreener()">
                                        <i class="fas fa-filter me-2"></i>
                                        AI选股器
                                    </button>
                                </div>
                                <div class="col-md-3 mb-3">
                                    <button class="quick-action-btn w-100" onclick="goToBacktest()">
                                        <i class="fas fa-chart-line me-2"></i>
                                        策略回测
                                    </button>
                                </div>
                                <div class="col-md-3 mb-3">
                                    <button class="quick-action-btn w-100" onclick="goToModelManagement()">
                                        <i class="fas fa-cogs me-2"></i>
                                        模型管理
                                    </button>
                                </div>
                                <div class="col-md-3 mb-3">
                                    <button class="quick-action-btn w-100" onclick="goToReports()">
                                        <i class="fas fa-file-alt me-2"></i>
                                        分析报告
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Bootstrap 5 JS -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    
    <script>
        // 设置当前日期
        document.getElementById('current-date').textContent = new Date().toLocaleDateString('zh-CN', {
            year: 'numeric',
            month: 'long',
            day: 'numeric',
            weekday: 'long'
        });

        // 模拟AI分析数据
        const mockOpportunities = [
            {
                code: '000001.SZ',
                name: '平安银行',
                rating: 'BUY',
                confidence: 85,
                reason: '财报数据超出市场预期，行业复苏迹象明显，AI舆情分析显示市场关注度正向激增',
                targetPrice: 18.50,
                currentPrice: 15.68
            },
            {
                code: '600519.SH', 
                name: '贵州茅台',
                rating: 'HOLD',
                confidence: 92,
                reason: '护城河稳固，但短期估值处于历史高位，建议继续持有并观察',
                targetPrice: null,
                currentPrice: 1680.00
            },
            {
                code: '300750.SZ',
                name: '宁德时代',
                rating: 'BUY',
                confidence: 78,
                reason: 'AI技术分析识别出潜在的"W底"反转形态，但需等待成交量确认信号',
                targetPrice: 220.00,
                currentPrice: 185.50
            }
        ];

        // 渲染机会卡片
        function renderOpportunities() {
            const container = document.getElementById('top-opportunities');
            
            const opportunitiesHTML = mockOpportunities.map(opp => {
                const ratingClass = opp.rating === 'BUY' ? 'rating-buy' : 
                                   opp.rating === 'HOLD' ? 'rating-hold' : 'rating-sell';
                const ratingText = opp.rating === 'BUY' ? '买入' : 
                                  opp.rating === 'HOLD' ? '持有' : '卖出';
                
                const upside = opp.targetPrice ? 
                    `<div class="text-success">
                        <small>目标价: ¥${opp.targetPrice.toFixed(2)}</small><br>
                        <small>上涨空间: ${((opp.targetPrice - opp.currentPrice) / opp.currentPrice * 100).toFixed(1)}%</small>
                    </div>` : '';

                return `
                    <div class="col-lg-4 mb-3">
                        <div class="ai-card opportunity-card h-100">
                            <div class="card-body">
                                <div class="d-flex justify-content-between align-items-start mb-3">
                                    <div>
                                        <h6 class="mb-1">${opp.name}</h6>
                                        <small class="text-muted">${opp.code}</small>
                                    </div>
                                    <span class="rating-badge ${ratingClass}">${ratingText}</span>
                                </div>
                                
                                <div class="mb-3">
                                    <div class="d-flex justify-content-between align-items-center mb-2">
                                        <small class="text-muted">AI信心指数</small>
                                        <span class="confidence-badge">${opp.confidence}%</span>
                                    </div>
                                </div>
                                
                                <p class="text-sm mb-3">${opp.reason}</p>
                                
                                <div class="d-flex justify-content-between align-items-center">
                                    <div>
                                        <small class="text-muted">当前价格</small><br>
                                        <strong>¥${opp.currentPrice.toFixed(2)}</strong>
                                    </div>
                                    ${upside}
                                </div>
                                
                                <div class="mt-3">
                                    <button class="btn btn-primary btn-sm w-100" onclick="viewDetailedAnalysis('${opp.code}')">
                                        查看AI完整分析报告 <i class="fas fa-arrow-right ms-1"></i>
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                `;
            }).join('');
            
            container.innerHTML = opportunitiesHTML;
        }

        // 页面加载完成后渲染数据
        document.addEventListener('DOMContentLoaded', function() {
            // 模拟加载延迟
            setTimeout(() => {
                renderOpportunities();
            }, 2000);
        });

        // 功能函数
        function refreshDashboard() {
            location.reload();
        }

        function viewDetailedAnalysis(stockCode) {
            window.open(`/stock/${stockCode}`, '_blank');
        }

        function addPortfolio() {
            alert('持仓管理功能开发中...');
        }

        function goToStockScreener() {
            window.location.href = '/screen';
        }

        function goToBacktest() {
            window.location.href = '/backtest';
        }

        function goToModelManagement() {
            window.location.href = '/ml_factor/models';
        }

        function goToReports() {
            window.location.href = '/reports';
        }
    </script>
</body>
</html>
